#include<iostream>
using std::cout;
using std::endl;

#include"shared.h"


struct A {
	A() {
		cout << "Creating A" << endl;
	}
	
	virtual ~A() {
		cout << "Freeing A" << endl;
	}
	
	virtual void hello() {
		cout << "I am A" << endl;
	}
};
	
struct B : A {
	
	B() {
		cout << "Creating B" << endl;
	}

	virtual void hello() {
		cout << "I am B" << endl;
	}
	
	virtual ~B() {
		cout << "Freeing B" << endl;
	}
};

int main() {
	shared_ptr<A> sp1(new B());
	shared_ptr<B> sp2(sp1);
	shared_ptr<B> sp3(new B());
	shared_ptr<A> sp4(sp3);
	sp1 -> hello();
	sp2 -> hello();
	sp3 -> hello();
	sp4 -> hello();
	sp3 = sp2;
	sp1 = sp2;
	sp2 = sp2;
	sp4 = sp1;
	sp1 = sp4;
	return 0;
}